﻿using MediatR;
using Traceability.Commont.Domains.AnimalsDomainFiles;
using Traceability.Commont.DTOs.CommontFiles;
using Traceability.Commont.Infrastructures.Interfaces;

namespace U.Enterprise.Api.Applications.Scalesetting
{
    public class ScaleSettingCreateHandler : IRequestHandler<ScaleSettingCreateCommond, Resqults>
    {

        private readonly IBateRepository<Scale> _Scale;

        public ScaleSettingCreateHandler(IBateRepository<Scale> scale)
        {
            _Scale = scale;
        }

        public async Task<Resqults> Handle(ScaleSettingCreateCommond request, CancellationToken cancellationToken)
        {
            var list=new Resqults() { Code=0};


            var query = new Scale()
            {
                Scaleid=request.Scaleid,
                ScaleName=request.ScaleName
                ,ScaleTypeId=request.ScaleTypeId,
                InAndOutOfStorage=request.InAndOutOfStorage,
                CreatedBy=request.CreatedBy,
                CreateTime=DateTime.Now,
                ModifiedBy=request.ModifiedBy,
                NumberOfPieces=request.NumberOfPieces,
                Operator=request.Operator,
                TareWeightDeduction=request.TareWeightDeduction,
                UseType=request.UseType,
                Warehouse=request.Warehouse,
            };


            var result=await _Scale.Add(query);
            if(result>0)
            {
                list.Code = 1;
            }

            return list;

        }
    }
}
